<%@ page contentType="text/html;charset=utf-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="/WEB-INF/tld/mytaglibs.tld" prefix="my" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<c:set var="ctxPath" value="${pageContext.request.contextPath}"/>
<title>单一实体</title>
<div class="page-header">
	<h1>单一实体<small><i class="ace-icon fa fa-angle-double-right"></i>[管理]</small></h1>
</div>

<div class="search_form">
	<div class="row">
		<div class="col-sm-12">
			<form class="form-horizontal" name="formQuery" action="" method="POST">
				<div class="col-sm-11">
					<div class="col-sm-1 control-label search-label">编号</div>
					<div class="col-sm-3 search-value">
						<input type="text" id="InputText" placeholder="" class="form-control input-sm" ng-model="test">
					</div>
					<div class="col-sm-1 control-label search-label">label2</div>
					<div class="col-sm-3 search-value">
						<input type="text" id="Text1" placeholder="" class="form-control input-sm">
					</div>
					<div class="col-sm-1 control-label search-label">label3</div>
					<div class="col-sm-3 search-value">
						<div class="input-group">
							<span class="input-group-addon"><i class="fa fa-phone"></i></span><input type="text" placeholder="" class="form-control input-sm">
						</div>
					</div>
					
					<div class="col-sm-1 control-label search-label">日期</div>
					<div class="col-sm-3 search-value">
						<div class="dateseach input-group">
							<input name="start" class="input-sm form-control" type="text">
							<span class="input-group-addon"><i class="fa fa-exchange"></i></span>
							<input name="end" class="input-sm form-control" type="text">
						</div>
					</div>
					<div class="col-sm-1 control-label search-label">label2</div>
					<div class="col-sm-3 search-value">
						<input type="text" id="Text3" placeholder="" class="form-control form-control-shadow input-sm">
					</div>
					<div class="col-sm-1 control-label search-label">label3</div>
					<div class="col-sm-3 search-value">
						<div class="input-group input-group-shadow">
							<span class="input-group-addon"><i class="fa fa-phone"></i></span> <input type="text" placeholder="" class="form-control input-sm">
						</div>
					</div>


				</div>
				<div class="col-sm-1 control-search">
					<div class="btn-group btn-group-vertical">
						<button type="button" class="btn btn-grey btn-sm search_btn" onclick="reset()"><i class="fa fa-refresh"></i>&nbsp;清空</button>
						<button type="reset" class="btn btn-success btn-sm search_btn" onclick="query()"><i class="fa fa-search"></i>&nbsp;查询</button>
					</div>
				</div>
			</form>
		</div>
	</div>
</div>

<div class="command_area">
	<div class="row">
		<div class="col-sm-12">
			<div class="pull-left">
			<div class="btn-group">
				<button type="button" class="btn btn-default btn-sm" onclick="add()" title="添加"><i class="fa fa-plus"></i>&nbsp;添加</button>
				<button type="button" class="btn btn-default btn-sm" onclick="edit()" title="修改"><i class="fa fa-file-text-o"></i>&nbsp;修改</button>
				<button type="button" class="btn btn-default btn-sm" onclick="remove()" title="删除"><i class="fa fa-trash-o"></i>&nbsp;删除</button>
			</div>
			</div>
			<div class="pull-right">
			<div class="btn-group">
				<button type="button" class="btn btn-default btn-sm" onclick="sortOrRefresh()" title="刷新"><i class="glyphicon glyphicon-repeat"></i>&nbsp;刷新</button>
			</div>
			</div>
		</div>
	</div>
</div>

<div class="row">
	<div class="col-sm-12">
		<div id="grid-table" style="position:relative;top:0px;left:0px;width:100%;height:450px;"></div>
		<div id="grid-pager"></div>
	</div>
</div>
<script type="text/javascript">
var mygrid;
var pager;

function fnLoad(){

}

function setButtonStatus(theFlag){
	
}

function doOnRowSelected(id){
	setButtonStatus(false);
}

function fnGridFinish(){
	setButtonStatus(true);
	pager.showDivPageDhtmx();
	var vError=mygrid.getUserData("", "error");
	if(vError){
		alert("错误:"+vError);
	}
}

function create(){
	window.location.href ="#page/entityOne/add.do";
}
function view(){
	var tmpKey = mygrid.getUserData(mygrid.getSelectedId(), "key");
    if(tmpKey == ""){
        alert("请选择要查看的数据!");
        return;
    }    
    var tmpURL = "${ctx}/entityOne/view.do?key="+tmpKey;
    window.location.href=tmpURL;
}
function remove(){
	//mygrid.setSizes();
	
	var tmpKey = mygrid.getUserData(mygrid.getSelectedId(), "key");
	if (tmpKey == null || tmpKey == "") {
		alert("请选择要删除的数据!");
		return;
	}
    if(confirm("警告:确定要删除此条记录?")){
		$.ajax({
    		async : false,
    		type : "post",
    		url : "${ctx}/entityOne/remove.do",
    		data : {
    			key : tmpKey
    		},
    		error : function() {
    			//alert("错误:请求服务响应失败!");
    		},
    		success : function(data) {
    			if (data == "success") {
    				var currentPage = getCurrentPage(mygrid);
    				var pageSize = getPageSize(mygrid);
    				search(currentPage, pageSize);
    			} else {
					alert(text);
				}
    		}
    	});
    }
}
function edit(){
	var tmpKey = mygrid.getUserData(mygrid.getSelectedId(), "key");
	if (tmpKey == null || tmpKey == "") {
		alert("请选择要修改的数据!");
		return;
	}	
	var tmpURL = "#page/entityOne/update.do?key=" + tmpKey;
	window.location.href = tmpURL;
}

function search(thePageNo,thePageSize,theStyle){
	var qryUrl = "${ctx}/entityOne/datagrid.do";
	qryUrl+="?prepend=where";
	
	qryUrl+="&pagesize="+thePageSize;
	qryUrl+="&pageno="+thePageNo;
	if(theStyle == "excel"){
		qryUrl += "&pagestyle=excel";
		window.location.href=qryUrl;
	}
	else{
		mygrid.clearAll();
		mygrid.loadXML(qryUrl,fnGridFinish);
	}
}
function query(theStyle){
	if(pager.divPageFlag){
		search(1,pager.pageSize,theStyle);
	}
	else {
		search(-1,-1,theStyle);
	}
}
function fnExcel(){
	if(pager.divPageFlag){
		search(1,pager.pageSize,"excel");
	}
	else {
		search(-1,-1,"excel");
	}
}

var scripts = [ null,null ];
				
$('.page-content-area').ace_ajax('loadScripts', scripts, function() {
	jQuery(function($) {
		<my:grid varGrid="mygrid" idGrid="grid-table" name="EntityOneGrid" splitAt="3" sort="true" create="true">
		<my:gridevent varGrid="mygrid" eventName="onRowSelect" eventMethod="doOnRowSelected" />
		</my:grid>
		
		pager=new PagerView("grid-pager",mygrid,30);
		pager.createDivPage();
		
		pager.onPageChanged = function(nextPage){
			setButtonStatus(true);
			search(nextPage,pager.pageSize);
		};
		
		pager.onGoClicked = function(pageNo,pageSize){
			setButtonStatus(true);
			search(pageNo,pageSize);
		};
		
		 //$(window).on('resize.page-content-area', function() {
		 //		alert("resize.page-content-area");
		 //});
		 
		
		var resizeGrid = function () {	    
		    mygrid._delta_y="200px";
		    mygrid.setSizes();
		};
		
		$(window).resize(resizeGrid);
		

		fnLoad();
		query();
	});
});	
</script>
